//
//  NewMingXinViewController.m
//  wangzhe
//
//  Created by 李 佳伟 on 2018/3/8.
//  Copyright © 2018年 李 佳伟. All rights reserved.
//

#import "NewMingXinViewController.h"
#import "JTCSM.h"
#import "LCChartView.h"
#import "MyDoubleLabelView.h"
#import "HuankuanJiluTableViewCell.h"
#import "NewDataInfoViewController.h"
#import "NewMingXinInfoViewController.h"
#import "NewMonthBaogaoViewController.h"

@interface NewMingXinViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    NSString *mykeyword;
}
@property (nonatomic,strong) NSMutableArray *titlearray;
@property (nonatomic,strong) UITableView *tableview;

@property (strong, nonatomic) LCChartView *chartViewLine;
@property (nonatomic,strong)  UILabel *headerDateLabel;
@property (nonatomic,strong) MyDoubleLabelView *leftDataDoubleView;
@property (nonatomic,strong) MyDoubleLabelView *bottomleftView;
@property (nonatomic,strong) MyDoubleLabelView *bottomrightView;

@end

@implementation NewMingXinViewController

- (void)gotoAddBankVC{
    NewMonthBaogaoViewController *vc = [[NewMonthBaogaoViewController alloc]init];
    vc.nameTitle = @"月报";
    [self.navigationController pushViewController:vc animated:YES];
}
#pragma 跳转日历
- (void)gotoDBVC{
    NewDataInfoViewController *vc = [[NewDataInfoViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view setBackgroundColor:[UIColor whiteColor]];
    leftBarButtonItems_rightBarButtonItems *leftbtn = KCUSTOMNAVIGSTION_ALLOC;
    self.navigationItem.rightBarButtonItem = [leftbtn setBarButtonItemsTitle:@"月统计" frame:KRightBarButtonItemFrame_text target:self SEL:@selector(gotoAddBankVC)];
    // Do any additional setup after loading the view.
    [self layoutTableView];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [df isRemoveTarbar:NO];
    self.navigationController.navigationBar.hidden = NO;
    
}
- (void)layoutTableView{
    
    _tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KCONTROLLERWith, KCONTROLLERHeight) style:UITableViewStylePlain];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    [self.view addSubview:_tableview];
    _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableview.tableHeaderView = [self layoutTableViewHeaderView];
    [self setUpTableView];
    //    view.backgroundColor = RGBACOLOR(241, 241, 241, 1);
}

- (void)setUpTableView{
    // 1.下拉刷新(进入刷新状态就会调用self的headerRereshing)
    [_tableview addHeaderWithTarget:self action:@selector(headerRereshing)];
    
    // 上拉加载
    [_tableview addFooterWithTarget:self action:@selector(footerRereshing)];
    
}
- (void)headerRereshing{
    // 2秒后刷新表格UI
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(KRefreshTime * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        //getMarriageSeeking(网络请求)
        //        [self theRequestWithKeyWord:mykeyword];
    });
}
- (void)footerRereshing{
    // 2秒后刷新表格UI
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(KRefreshTime * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        //getMarriageSeeking(网络请求)
        //        [self loadMoreDataRequestWithKeyWord:mykeyword];
        
    });
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString *cellid = [NSString stringWithFormat:@"textfield%ld",(long)indexPath.row];
    HuankuanJiluTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid];
    if (cell == nil) {
        cell = [[HuankuanJiluTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid cellType:IsZhangDanType];
    }
    [cell setValueWithModel:indexPath];
    cell.stateLabel.text = @"14345.00";
    cell.stateLabel.textColor = [df colorWithHexString:@"333333" alpha:1];
    cell.bottomstateLabel.text = @"-3.70";
    return cell;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 75;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NewMingXinInfoViewController *vc = [[NewMingXinInfoViewController alloc]init];
    vc.nameTitle = @"详情";
    [self.navigationController pushViewController:vc animated:YES];

}

- (UIView *)layoutTableViewHeaderView{
    
    CGFloat headerviewHeight = 249;
    CGFloat space = 20;
    UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 64, KCONTROLLERWith, headerviewHeight)];
    headerView.backgroundColor = RGBACOLOR(241, 241, 241, 1);
    headerView.userInteractionEnabled = YES;
    
    self.headerDateLabel = [UILabel initWithFrame:CGRectMake(space, 0, KCONTROLLERWith/2, 36) text:@"04月11日" font:13 textAlignment:NSTextAlignmentLeft texcolor:RGBACOLOR(51, 51, 51, 1) backgroundColor:nil];
    [headerView addSubview:self.headerDateLabel];
    
    CGFloat dateImageSize = 20;
    UIImageView *dateImageV = [[UIImageView alloc]initWithFrame:CGRectMake(KCONTROLLERWith-space-dateImageSize, 8, dateImageSize, dateImageSize)];
    dateImageV.image = [UIImage imageNamed:@"明细_日历.png"];
    [headerView addSubview:dateImageV];
    dateImageV.userInteractionEnabled = YES;
    [df addTapGestureRecognizerWithTarget:self action:@selector(gotoDBVC) andaddView:dateImageV];
    
    CGFloat dataViewWidth = KCONTROLLERWith*0.328;
    UIView *leftdataView = [[UIView alloc]initWithFrame:CGRectMake(0, KVIEW_Y(self.headerDateLabel), dataViewWidth, 120)];
    leftdataView.backgroundColor = [UIColor whiteColor];
    [headerView addSubview:leftdataView];
    
    self.leftDataDoubleView = [[MyDoubleLabelView alloc]initWithFrame:CGRectMake(20, 30, leftdataView.LC_width-20, 0) leftTitleFontsize:17 titlecolor:RGBACOLOR(51, 51, 51, 1) contentFontsize:12 contentcolor:[df colorWithHexString:@"666666" alpha:1]];
    [leftdataView addSubview:self.leftDataDoubleView];
    [self.leftDataDoubleView setvalueWithModel:@{KDoubleLabelTitle:@"183450.00",KDoubleLabelContent:@"32884387笔"}];
    NSString *str = @"共计";
    CGFloat font = 9;
    CGRect alertRect = [df labelHeightWithContent:str width:100 font:font];
    UILabel *alertLabel = [UILabel initWithFrame:CGRectMake(20, KVIEW_Y(self.leftDataDoubleView)+5, alertRect.size.width+5, alertRect.size.height+5) text:str font:font textAlignment:NSTextAlignmentCenter texcolor:[UIColor whiteColor] backgroundColor:[df colorWithHexString:@"ffa018" alpha:1]];
    [df layerWithView:alertLabel radius:4 width:0 color:nil];
    [leftdataView addSubview:alertLabel];
    
    UIView *rightdataView = [[UIView alloc]initWithFrame:CGRectMake(KCONTROLLERWith*0.328+1, KVIEW_Y(self.headerDateLabel), KCONTROLLERWith-dataViewWidth-1, 120)];
    rightdataView.backgroundColor = [UIColor whiteColor];
    [headerView addSubview:rightdataView];
    _chartViewLine = [LCChartView chartViewWithType:LCChartViewTypeLine];
    _chartViewLine.frame = CGRectMake(20, 10, rightdataView.LC_width-1, 90);
    [rightdataView addSubview:self.chartViewLine];
    LCChartViewModel *model = [LCChartViewModel modelWithColor:KZhuTiRGB plots:[self randomArrayWithCount:1000] project:@""];
    [self.chartViewLine showChartViewWithYAxisMaxValue:1000 dataSource:@[model]];
    
    [df newlineViewWithHeightofTop:166 superView:headerView spacing:0 color:RGBACOLOR(241, 241, 241, 1) lineHeight:10];
    
    UIView *bottomdataView = [[UIView alloc]initWithFrame:CGRectMake(0, 166, KCONTROLLERWith, 80)];
    bottomdataView.backgroundColor = [UIColor whiteColor];
    [df lineViewWithWidthtofLeft:KCONTROLLERWith/2-0.5 superView:bottomdataView spacing:10 color:RGBACOLOR(241, 241, 241, 1) lineWidth:1];
//    [df newlineViewWithHeightofTop:80 superView:bottomdataView spacing:20 color:RGBACOLOR(241, 241, 241, 1) lineHeight:1];
    [headerView addSubview:bottomdataView];
    
    self.bottomleftView = [[MyDoubleLabelView alloc]initWithFrame:CGRectMake(0, 0, KCONTROLLERWith/2, bottomdataView.LC_height) titleFontsize:17 titlecolor:RGBACOLOR(51, 51, 51, 1) contentFontsize:12 contentcolor:[df colorWithHexString:@"666666" alpha:1]];
    [bottomdataView addSubview:self.bottomleftView];
    [self.bottomleftView InsertSpacesetvalueWithModel:@{KDoubleLabelTitle:@"183450.00",KDoubleLabelContent:@"净收益（元）"} changeLabelY:10];
    
    self.bottomrightView = [[MyDoubleLabelView alloc]initWithFrame:CGRectMake(KCONTROLLERWith/2, 0, KCONTROLLERWith/2, bottomdataView.LC_height) titleFontsize:17 titlecolor:RGBACOLOR(51, 51, 51, 1) contentFontsize:12 contentcolor:[df colorWithHexString:@"666666" alpha:1]];
    [bottomdataView addSubview:self.bottomrightView];
    [self.bottomrightView InsertSpacesetvalueWithModel:@{KDoubleLabelTitle:@"183450.00",KDoubleLabelContent:@"手续费（元）"} changeLabelY:10];
    
    return headerView;
    
}





















- (NSArray *)randomArrayWithCount:(NSInteger)dataCounts {
    NSMutableArray *array = [[NSMutableArray alloc] init];
    for (int i = 0; i < dataCounts; i++) {
        NSString *number = [NSString stringWithFormat:@"%d.%d%d",arc4random_uniform(1000),arc4random_uniform(9),arc4random_uniform(9)];
        [array addObject:number];
    }
    return array.copy;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
